# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Sören Tempel <soeren+alpine@soeren-tempel.net>
pkgname=stlink
pkgver=1.6.1
pkgrel=0
pkgdesc="STM32 discovery line linux programmer"
url="https://github.com/texane/stlink"
arch="all"
license="MIT"
makedepends="cmake libusb-dev"
options="!check" # upstream doesn't have automated tests
subpackages="$pkgname-doc $pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/texane/stlink/archive/v$pkgver.tar.gz
	0001-doc-man-Fix-installation-directory.patch
	0002-CMakeLists.txt-Install-pkgconfig-files-again.patch"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DBUILD_SHARED_LIBS=True \
		-DSTLINK_LIBRARY_PATH=/usr/lib \
		-DCMAKE_C_FLAGS="$CFLAGS -Wno-error=cpp" \
		$CMAKE_CROSSOPTS .
	make -C build
}

package() {
	make -C build DESTDIR="$pkgdir" install

	mkdir -p "$pkgdir"/usr/share/doc/$pkgname
	install -m644 README.md CHANGELOG.md doc/tutorial.md \
		"$pkgdir"/usr/share/doc/$pkgname/

	mkdir -p "$pkgdir"/usr/lib/udev
	mv "$pkgdir"/etc/udev/rules.d "$pkgdir"/usr/lib/udev
}

sha512sums="ac7ca0c23cd82a66be3ade4fec2a3fe757e5fc2e1d5c68a81316781a59568261a363efb58f5c529921b1c97185489fca5f1c1c4681098c72fb121b0858916fbc  stlink-1.6.1.tar.gz
0825e51e46b65ad5c24d18edcd301823f02e8979dd793ada292eae3ac6d61cd32945a5ba8e102bc320991bbcd2cc5015a909f41e4c0a57aeed39aaff8b96d97f  0001-doc-man-Fix-installation-directory.patch
d31ecbbe5458ac0de20ca26277031c375da73ef600eec305b1c199d21560add6448a6b3086f3c60350d001dcc5f2a1113ed723fbc177c6bd1d02bdd868a9bfe0  0002-CMakeLists.txt-Install-pkgconfig-files-again.patch"
